<template>
	<view style="flex: 1;">
		<camera style="width: 100%; height: 300px;" :resolution="'medium'" :device-position="devicePosition" 
			:flash="flash" :frame-size="frameSize" @stop="handleStop" @error="handleError" @initdone="handleInitDone">
		</camera>

		<view>
			<button type="default" @click="handleScanCode">扫码</button>
			<button type="default" @click="switchDevicePosition">切换前后摄像头</button>
			<button type="default" @click="switchFlash">闪光灯</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				devicePosition: "back",
				flash: "off",
				frameSize: "medium"
			}
		},

		methods: {
			handleScanCode() {
        		uni.navigateTo({
          			url:"/pages/camera/camera-scan-code"
        		})
      		},
			
			switchDevicePosition() {
				this.devicePosition = this.devicePosition == "back" ? "front" : "back"
			},

			switchFlash() {
				this.flash = this.flash == "torch" ? "off" : "torch"
			},

			handleStop(e) {
				console.log("stop", e.detail);
			},
			
			handleError(e) {
				console.log("error", e.detail);
			},
			
			handleInitDone(e) {
				console.log("initdone", e.detail);
			}
		}
	}
</script>

<style>

</style>